#include<iostream>
using namespace std;
#include<stack>
#include<cstring>
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		string str;
		cin >> str;
		stack<char> s;
		for (int j = 0; j < str.length(); j++) {
			if (str[j] == '#'&&!s.empty()) {
				s.pop();
			}
			else if (str[j] == '#' && s.empty()) {
				continue;
			}
			else {
				s.push(str[j]);
			}
		}
		if (s.size()) {
			int len = s.size();
			char* p = new char[len];
			for (int j = 0; j < len; j++) {
				p[j] = s.top();
				s.pop();
			}
			for (int j = len - 1; j >= 0; j--) {
				cout << p[j];
			}
			cout << endl;
		}
		else {
			cout << "NULL" << endl;
		}
	}
}